package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.dao.ContractSurchargeDao;
import com.xbongbong.saas.domain.entity.ContractSurchargeEntity;
import com.xbongbong.saas.model.ContractSurchargeModel;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/2/23 15:57
 * @since v1.0
 */
@Service("contractSurchargeModel")
public class ContractSurchargeModelImpl implements ContractSurchargeModel {
    @Resource
    private ContractSurchargeDao contractSurchargeDao;

    @Override
    public Integer insert(ContractSurchargeEntity entity) throws XbbException {
        return contractSurchargeDao.insert(entity);
    }

    @Override
    public Integer update(ContractSurchargeEntity entity) throws XbbException {
        return contractSurchargeDao.update(entity);
    }

    @Override
    public List<ContractSurchargeEntity> findEntitys(Map<String, Object> param) {
        return contractSurchargeDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return contractSurchargeDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public ContractSurchargeEntity getByKey(Long key, String corpid) {
        return contractSurchargeDao.getByKey(key, corpid);
    }

    @Override
    public List<ContractSurchargeEntity> getContractSurchargeListByIdIn(String corpid, List<Long> contractIdIn) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("contractIdIn", contractIdIn);
        param.put("del", 0);
        return findEntitys(param);
    }

    @Override
    public List<ContractSurchargeEntity> getContractSurchargeList(String corpid, Long contractId) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("contractId", contractId);
        param.put("del", 0);
        return findEntitys(param);
    }

    @Override
    public Integer deleteByKey(Long key, String corpid) {
        return contractSurchargeDao.deleteByKey(key, corpid);
    }

    @Override
    public Integer deleteBatch(List<Long> idIn, String corpid) {
        return contractSurchargeDao.deleteBatch(idIn, corpid);
    }

    @Override
    public Integer deleteBatchByContractId(List<Long> deleteIdIn, String corpid) {
        if (CollectionUtils.isEmpty(deleteIdIn)) {
            return 0;
        }
        return contractSurchargeDao.deleteBatchByContractId(deleteIdIn, corpid);
    }
}
